﻿/**
* 提交表表单数据
**/
function sumbitData(dg,dlg,fm) {

    $.messager.progress({
        title: '请等待',
        msg: '加载数据中...'
    });

    if (!fm) fm = $("form");

    var result = fm.form('enableValidation').form('validate');
    if(result)
    {
        fm.ajaxSubmit({
            complete: function () {
                $.messager.progress('close');
            },
            success: function (responseText) {
                if (responseText != undefined) {
                    if (responseText.length >= 1) {
                        $.messager.alert('错误提示', responseText, "error");
                    }
                    else {
                        dg.data().datagrid.selectRowIndex = null;
                        dg.datagrid('reload');
                        dlg.dialog('close');
                    }
                }
                else {
                    dg.data().datagrid.selectRowIndex = null;
                    dg.datagrid('reload');
                    dlg.dialog('close');
                }

            },
            error: printError
        });
    }
    else
    {
        $.messager.progress('close');
        $.messager.alert('验证失败', '请修改填写错误的数据,红色框框的数据代表错误!');
    }
   
}

function deleteData(dg, dlg, url) {
    $.messager.confirm('删除提示', '你确定需要删除?', function (r) {
        if (r) {
            $.ajax({
                type: "Delete",
                url: url,
                data: dg.datagrid('getSelected'),
                success: function () {
                    dg.data().datagrid.selectRowIndex = null;
                    dg.datagrid("getPager").pagination('select', 1);
                    if (dlg) dlg.dialog('close');
                },
                error: printError
            });
        }
    });  
}

/**
*扩展easyui表单的验证  
**/
$.extend($.fn.validatebox.defaults.rules, {
    //验证汉字  
    CHS: {
        validator: function (value) {
            return /^[\u0391-\uFFE5]+$/.test(value);
        },
        message: 'The input Chinese characters only.'
    },
    //移动手机号码验证  
    Mobile: {//value值为文本框中的值  
        validator: function (value) {
            var reg = /^1[3|4|5|8|9]\d{9}$/;
            return reg.test(value);
        },
        message: 'Please enter your mobile phone number correct.'
    },
    //国内邮编验证  
    ZipCode: {
        validator: function (value) {
            var reg = /^[0-9]\d{5}$/;
            return reg.test(value);
        },
        message: 'The zip code must be 6 digits and 0 began.'
    },
    //数字  
    Number: {
        validator: function (value) {
            var reg = /^[0-9]*$/;
            return reg.test(value);
        },
        message: 'Please input number.'
    },
    MinLength: {
        validator: function (value, param) {   //value 为需要校验的输入框的值 , param为使用此规则时存入的参数
            return value.length >= param[0];
        },
        message: '请输入最小{0}位字符.'
    },
    MaxLength: {
        validator: function (value, param) {
            return param[0] >= value.length;
        },
        message: '请输入最大{0}位字符.'
    },
    Length: {
        validator: function (value, param) {
            return value.length >= param[0] && param[1] >= value.length;
        },
        message: '请输入{0}-{1}位字符.'
    },
    Equals: {
        validator: function (value, param) {
            return value == $(param[0]).val();
        },
        message: '字段不相同.'
    },
    Web: {
        validator: function (value) {
            return /^(http[s]{0,1}|ftp):\/\//i.test($.trim(value));
        },
        message: '网址格式错误.'
    },
    Date: {
        validator: function (value) {
            return /^[0-9]{4}[-][0-9]{2}[-][0-9]{2}$/i.test($.trim(value));
        },
        message: '曰期格式错误,如2012-09-11.'
    },
    Email: {
        validator: function (value) {
            return /^[a-zA-Z0-9_+.-]+\@([a-zA-Z0-9-]+\.)+[a-zA-Z0-9]{2,4}$/i.test($.trim(value));
        },
        message: '电子邮箱格式错误.'
    }
})
